/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author pt-user
 */
public class CGetAllImageFile {

    // File representing the folder that you select using a FileChooser
    static File dir = new File("C:");
    // array of supported extensions (use a List if you prefer)
    static String[] EXTENSIONS = new String[]{
        "gif", "png", "bmp", "jpg" // and other formats you need
    };
    // filter to identify images based on their extensions
    static FilenameFilter IMAGE_FILTER = new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            for (final String ext : EXTENSIONS) {
                if (name.endsWith("." + ext)) {
                    return (true);
                }
            }
            return (false);
        }
    };

    public static void parseAllFiles(String parentDirectory) {

        String rootDir = System.getenv("SystemDrive");
        System.out.println("PARSED FILES ::" + rootDir);

        File[] filesInDirectory = new File(parentDirectory).listFiles();
        if (filesInDirectory != null) {
            for (File f : filesInDirectory) {
                if (f.isDirectory()) {
                    parseAllFiles(f.getAbsolutePath());
                }
                System.out.println("Current File -> " + f);
                System.out.println(f.getPath());

                File f1 = new File(f.getPath() + "process_list.txt");

                System.out.println("filename : " + f1.exists());


                boolean exists = f1.exists();
                System.out.println("exists : " + exists);
                if (exists) {
                    System.out.println("Path::" + f1.getPath());
                } else {
                    System.out.println("Does not exist");
                }
            }
        }
    }
    File[] files = File.listRoots();
    //for(File f : files)

    {
        // parse
    }

    /**
     *
     * @param args
     */
    public static void main(String[] args) {

        if (dir.isDirectory()) { // make sure it's a directory
            for (final File file : dir.listFiles(IMAGE_FILTER)) {
                BufferedImage img = null;

                try {
                    img = ImageIO.read(file);

                    // you probably want something more involved here
                    // to display in your UI
                    System.out.println("image: " + file.getName());
                    System.out.println(" width : " + img.getWidth());
                    System.out.println(" height: " + img.getHeight());
                    System.out.println(" size  : " + file.length());

                    File[] files = File.listRoots();
                    for (File f : files) {
                        parseAllFiles(f.getPath());
                    }
                } catch (final IOException e) {
                    // handle errors here
                }
            }
        }
    }
}
